<?php
require('inc/db.php');

if($_POST['title'])
{
    if($_POST['post_id'])
    {
        mysql_query("
        UPDATE post SET `title`= '".$_POST['title']."',`content`='".nl2br($_POST['content'])."', `post_time` = ".time()." WHERE id = ".$_POST['post_id']."
        ");
        die('编辑成功，<a href="riji.php?id='.$_POST['post_id'].'">查看');
    }
    else
    {
        mysql_query("
        INSERT INTO post (`title`,`category`,`content`,`post_time`) 
        VALUES ('".$_POST['title']."','".$_POST['category']."','".nl2br($_POST['content'])."',".time().")");
        $id = mysql_insert_id();
        die('发布成功，<a href="riji.php?id='.$id.'">查看');
    }
}
?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>写日记</title>
    <link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="header">
    <p class="de">想了解未来，就关注现在</p>
    <div id="logo">
        <a href="/about">写意天空</a>
    </div>
    <div id="nav">
        <a href="index.php">首页</a>
        <a href="list.php">狐言</a>
        <a href="pictures.php">图片</a>
        <a href="archives.php">归档</a>
        <a href="about.php">关于</a>
        <a href="links.php">链接</a>
    </div>
</div>
<div id="contact">
<div id="post">

<form method="post" action="post.php">
    <table border="0">
        <tr>
            <td>标题</td>
        </tr>
        <tr>
            <td align="left"><input type="text"name="title"size="30" maxlength="300"></td>
        </tr>
        <tr >
            <td>分类</td>
        </tr>
        <tr>
            <td align="left"><input type="text"name="category"size="30" maxlength="300"></td>
        </tr>
        <tr>
            <td>内容</td>
        </tr>
        <tr>
            <td><textarea name="content" rows="16" cols="88"></textarea></td>
        </tr>
        <tr>
            <td colspan="2" align="left"><input type="submit" value="submit order"/></td>
        </tr>
    </table>
</form>
</body>
</html>